import React, {Component, PropTypes} from 'react';
import Signals from 'signals';
import styles from './Main.less';
import SubEditListContainer from '../Table/SubEditListContainer';
import CatEditListContainer from '../Table/CatEditListContainer';
import {getCatBySubId} from "../../services/showServer";

class SubManMainContainer extends React.Component {
  constructor(props) {
    super(props);
    //signals事件
    this.signal = new Signals.Signal();
  }

  componentWillMount() {
    this.signal.add(function (sub) {
      getCatBySubId(sub.id).then(function (json) {
        this.refs.catlist.setState({
          subId: sub.id,
          subName: sub.name,
          dataFilter: json,
          dataSource: json
        });
      }.bind(this));
    }.bind(this));
  }

  componentWillUnmount() {
    this.signal.removeAll();
  }

  render() {
    return (
      <div className={styles.content}>
        <div className={styles.sub_side}>
          <SubEditListContainer signal={this.signal} ref="sublist"/>
        </div>
        <div className={styles.cat_side}>
          <CatEditListContainer signal={this.signal} ref="catlist"/>
        </div>
      </div>
    );
  }
}

export default SubManMainContainer;
